#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>

#define DEV_NAME	"/dev/hello"

int main()
{
	int fd = 0;
    char *buf;
    int len;
    char str[1024];

	fd = open(DEV_NAME,O_RDWR);
	if(fd < 0){
		perror("can not open file /dev/hello!\n");
		exit(1);
	}

    buf = mmap(NULL, 1024*8, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if(buf == MAP_FAILED){
        printf("can not open mmap file /dev/hello\n");
        return -1;
    }
    printf("mmap address = 0x%x\n" ,buf);
    printf("buf origin data = %s\n", buf);

    strcpy(buf, "new");

    read(fd, str, 1024);
    if(strcmp(buf, str) == 0){
        printf("compare ok!\n");
    }else{
        printf("compare err!\n");
        printf("str = %s!\n", str);
        printf("buf = %s!\n", buf);
    }
    
    while(1){
        sleep(1);
    }
	close(fd);
	return 0;
}
